<!DESCRIPTION>Validates an input field to make sure that only a number or character is entered. If you enter a number or a letter everything you can continue on. But, try entering another value like an exclamation point (!), an ampersand (&), or a dollar sign ($) and see what happens. It even highlights the incorrect entry field for you. <!/DESCRIPTION>
<!CATEGORY>Forms<!/CATEGORY>
<!SCRIPT>
<!-- START OF SCRIPT -->
<!-- HOW TO INSTALL VALIDATION (NUM. OR CHARS):
1. Copy code into the HEAD section of document
2. Put last coding into the BODY section of document -->
<!-- STEP ONE: Add code into HEAD section of document -->
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function validate(field) {
var valid = "abcdefghijklmnopqrstuvwxyz0123456789"
var ok = "yes";
var temp;
for (var i=0; i<field.value.length; i++) {
temp = "" + field.value.substring(i, i+1);
if (valid.indexOf(temp) == "-1") ok = "no";
}
if (ok == "no") {
alert("Invalid entry! Only characters and numbers are accepted!");
field.focus();
field.select();
}
}
// End -->
</script>
</HEAD>
<!-- STEP TWO: Add code into BODY section of document -->